package com.kaishengit.pms.web;


import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.kaishengit.pms.entity.Employee;
import com.kaishengit.pms.service.LoginService;

public class UpdatePwdServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;
	
	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		HttpSession session = request.getSession();
		Employee employee = (Employee)session.getAttribute("session_em");
		String password = employee.getPassword();
		String oldPwd = request.getParameter("oldPwd");
		String newPwd = request.getParameter("newPwd");
		String scPwd = request.getParameter("scPwd");
		
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		
		if(password.equals(oldPwd)){
			if(newPwd.equals(scPwd)){
				out.print("ok");
				LoginService  ls = new LoginService();
				ls.upPwd(employee.getId(),newPwd);
			}else{
				out.print("error2");
			}
		}else{
			out.print("error1");
		}
		out.flush();
		out.close();
	}
}
